package example.players;

import roshambo.Player;

public class IvanEquilibrium implements Player {

    /**
     * Conta as partidas
     */
    private int cont;
    /**
     * tipo de movimento
     */
    private int move;
    private int[] historyP1;

    @Override
    public int play() {
        cont++;
        equilibrium();
        historyP1[move]++;
        return move;
    }

    @Override
    public void newGame(int games) {
        move = PEDRA;
        cont = 0;
        historyP1 = new int[4];
        historyP1[PEDRA] = historyP1[PAPEL] = historyP1[TESOURA] = 0;
    }

    private void equilibrium() {
//        System.out.println(Arrays.toString(historyP1));
//        System.out.println("move:" + move);
        if ((double) historyP1[PEDRA] / cont < 0.3333333333) {
            move = PEDRA;
        } else if ((double) historyP1[PAPEL] / cont < 0.3333333333) {
            move = PAPEL;
        } else if ((double) historyP1[TESOURA] / cont < 0.3333333333) {
            move = TESOURA;
        }
//        System.out.println("move:" + move);

    }

    @Override
    public void receive(int result) {
    }

}
